import os
from fnmatch import fnmatch
from os.path import join, getsize


def find_dirs(root,  *pats):
    """ find dirs that have certain files 
    
    [ ('dir1', (filepat1. filepat2)), ('dir2,...)
    
    """
    for dname, dirs, files in os.walk(os.path.expanduser(root)):
        print dname
        fpats = None
        
        bn = os.path.basename(dname)
        for pat in pats:
            if fnmatch(bn,  pat[0]):
                fpats = pat[1]
                break
        if not fpats:
            continue
        # dirname ok, are all the file pats matched...
            
        all_match = True
        for p in fpats:
            mathes = [f for f in files if fnmatch(f,  p)]
            if not mathes:
                all_match = False
                break
        if all_match:
            yield dname

dirs = find_dirs('~', 
                     ('glib', ['gmain.c', 'gtypes.h']), 
                     ('gobject',  ['gtype.c', 'gvalue.c']))
                     
                     
print list( dirs )
